package com.tdrc.common.service;

import com.tdrc.common.beans.Role;
import com.tdrc.common.mapper.RoleMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author dpf
 * @version 1.0
 * @date 2020-4-23 17:35
 * @instruction ...
 */
@Service
//@CacheConfig(cacheNames="roleCache")
public class RoleService implements IRoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public int addRole(Role role) {
        return roleMapper.addRole(role);
    }

    @Override
    public void updateRole(Role role) {
        roleMapper.updateRole(role);
    }

    @Override
    public void deleteRole(Integer roleId) {
        roleMapper.deleteRole(roleId);
    }
    //@Cacheable(value = "roleList")
    @Override
    public List<Role> listRole(String roleName) {
        return roleMapper.listRole(roleName);
    }

    @Override
    public void addRoleMenu(int roleId, List<Integer> menuIds) {
        roleMapper.addRoleMenu(roleId,menuIds);
    }

    @Override
    public void deleteRoleMenuByRoleId(Integer roleId) {
        roleMapper.deleteRoleMenuByRoleId(roleId);
    }

    @Override
    public int checkRoleNameUnique(String  roleName) {
        int result = roleMapper.checkRoleNameUnique(roleName);
        if(result>0){
            return 3001;
        }else{
            return 0;
        }
    }

    @Override
    public List<Map<String, Object>> getRoleMenuByRoleId(Integer roleId) {

        return roleMapper.getRoleMenuByRoleId(roleId);

    }
}
